<template>
<div ref="mbox">
  <detail-header>detail-header</detail-header>
  <detail-banner :sightName="sightName" :vNumber="vNumber" :bannerImg="bannerImg" :gallaryImgs="gallaryImgs">detail-banner</detail-banner>  
  <detail-list :list="list">detail-banner</detail-list> 
  <div @click="goTop()" ref="abc">abcdefg</div> 
</div>
</template>
<script>
import DetailBanner from './components/Banner'
import DetailHeader from './components/Header'
import DetailList from './components/List'
import axios from 'axios'
export default {
  name: 'Detail',
  components: {
    DetailBanner,
    DetailHeader,
    DetailList    
  },
  data () {
    return{    
      sightName:'',
      bannerImg:'',
      vNumber:'',
      list:[],
      gallaryImgs:[],
      lastID:''
    }
  },
  methods:{
    getDetailList () {
      axios.get('/api/detail.json',{
         params:{
           id: this.$route.params.id
         }
      }).then(this.getDetailInfo)
      this.lastID = this.$route.params.id
    },
    getDetailInfo (res){
      res = res.data
      if(res.ret && res.data){
        const data = res.data
        this.sightName = data.sightName
        this.bannerImg = data.bannerImg
        this.vNumber = data.vNumber
        this.list = data.categoryList 
        this.gallaryImgs = data.gallaryImgs 
        //console.log(this.gallaryImgs)
      }            
    },
    goTop(){
      window.scrollTo(0,0)
      console.log(this.$refs.mbox.offsetTop + '|' +this.$refs.abc.offsetTop)
    }  
  },
  mounted () {
    this.getDetailList()
  },
  activated () {
    if(this.lastID != this.$route.params.id)
    {
      this.getDetailList() 
      console.log('I am activated'+this.lastID +'new id:'+ this.$route.params.id)//使用了keep-alive时会执行activated
    }   
  }
}
</script>
<style>
</style>
